package com.huanuo.internetofthings.controller.resources;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.unicorn.framework.core.ResponseDto;
import org.unicorn.framework.core.SysCode;
import org.unicorn.framework.core.exception.PendingException;

import com.huanuo.internetofthings.bo.userRole.UserRole;
import com.huanuo.internetofthings.service.resources.UserResourcesFacadeService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 资源表 前端控制器
 * </p>
 *
 * @author xiebin
 * @since 2018-07-23
 */
@RestController
@RequestMapping("/resources")
@Api(value = "资源模块", tags = { "资源模块" })
public class ResourcesController {
	@Autowired
    private UserResourcesFacadeService userResourcesFacadeService;
	
	@ApiOperation("功能列表")
	@RequestMapping(value = { "/list" }, method = { RequestMethod.GET })
	public ResponseDto<?> list() throws PendingException {
		//获得用户信息
		String userIdentity = (String) SecurityUtils.getSubject().getPrincipal();
		if (StringUtils.isBlank(userIdentity)) {
			throw new PendingException(SysCode.SESSION_ERROR);
		}
		UserRole userRole = new UserRole();
		userRole.setUserIdentity(userIdentity);
		return new ResponseDto<>(userResourcesFacadeService.getUserResourcesList(userRole));
	}

}
